<div class="returnproduct-manage">
    <div nz-row nzGutter="5">
        <div nz-col nzSpan="2">
            <label class="line-height-32-prefix">采购订单号：</label>
        </div>
        <div nz-col nzSpan="3">
            <input nz-input appHotSearch (hotSearchEmit)="handleSearch()" placeholder="输入采购订单号" [(ngModel)]="searchOrderCode" />
        </div>
        <div nz-col nzSpan="2">
            <label class="line-height-32-prefix">物料编码：</label>
        </div>
        <div nz-col nzSpan="3">
            <input nz-input appHotSearch (hotSearchEmit)="handleSearch()" placeholder="输入物料编码" [(ngModel)]="searchCode"/>
            <!-- <button nz-button nzType="primary">...</button> -->
        </div>
        <div nz-col nzSpan="2">
            <label class="line-height-32-prefix">物料名称：</label>
        </div>
        <div nz-col nzSpan="3">
            <input nz-input appHotSearch (hotSearchEmit)="handleSearch()" placeholder="输入物料编码" [(ngModel)]="searchName"/>
        </div>
        <!-- <div nz-col nzSpan="4">
            <button nz-button nzType="primary" (click)="handleSearch()">查询</button>
            <button nz-button nzType="primary" (click)="add()" class="margin-left-16">创建单据</button>
        </div> -->
        <div nz-col nzSpan="2">
            <label class="line-height-32-prefix">业务类型：</label>
        </div>
        <div nz-col nzSpan="3">
            <nz-select nzDropdownClassName="select_custom" [(ngModel)]="bizType" nzPlaceHolder="全部" class="width-10000" (ngModelChange)="bizTypeChange($event)">
                <nz-option nzValue="" nzLabel="全部"></nz-option>
                <nz-option nzValue="1" nzLabel="换货单"></nz-option>
                <nz-option nzValue="0" nzLabel="退货单"></nz-option>
            </nz-select>
        </div>
        <div nz-col nzSpan="2">
            <label class="line-height-32-prefix">检验状态：</label>
        </div>
        <div nz-col nzSpan="2">
            <nz-select nzDropdownClassName="select_custom" [(ngModel)]="InspectionStatus" nzPlaceHolder="全部" class="width-10000" (ngModelChange)="InspectionStatusChange($event)">
                <nz-option nzValue="" nzLabel="全部"></nz-option>
                <nz-option nzValue="0" nzLabel="无需检验"></nz-option>
                <nz-option nzValue="1" nzLabel="待检"></nz-option>
                <nz-option nzValue="2" nzLabel="合格"></nz-option>
                <nz-option nzValue="3" nzLabel="不合格"></nz-option>
                <nz-option nzValue="4" nzLabel="让步放行"></nz-option>
            </nz-select>
        </div>
    </div>
    <div nz-row nzGutter="16" class="margin-top-16">
        <div nz-col nzSpan="4">
            <!-- <button nz-button nzType="primary" (click)="handleSearch()">查询</button> -->
            <button nz-button nzType="primary" (click)="add()" *ngIf="returnchangeRoles.add">创建单据</button>
        </div>
    </div>
    <div nz-row class="row_2 margin-top-16">
        <nz-table #returnTable nzBordered nzTitle="退换单信息" [nzData]="listData" [nzFrontPagination]="false"  nzSize="small">
            <thead>
                <tr>
                    <th colspan="1">选择</th>
                    <th>单号</th>
                    <th>采购订单号</th>
                    <th>采购人员</th>
                    <th>创建时间</th>
                    <th>业务类型</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let data of returnTable.data">
                    <td nzShowCheckbox [(nzChecked)]="data.checked" (nzCheckedChange)="checkSingle(data)">
                    </td>
                    <td>{{ data.returncode }}</td>
                    <td>{{ data.pocode }}</td>
                    <td>{{ data.cgPerson }}</td>
                    <td>{{ data.createDate }}</td>
                    <td>
                        {{ data.returntype != null ? 
                            data.returntype == "0" ? "退货" 
                            : data.returntype == "1" ? "换货" 
                            : ""
                         : "" }}
                    </td>
                    <td>
                        <a href="javascript:;" (click)="showBox4(data, 1)">删除</a>
                    </td>
                </tr>
            </tbody>
        </nz-table>
        <div nz-row class="row_4" *ngIf="listData.length!=0" class="page_box" style="margin-top: 20px;">
            <nz-pagination (nzPageIndexChange)="clickPage($event)" [(nzPageIndex)]="pageIndex" [nzTotal]="totalSize"
                [nzShowTotal]="totalTemplate"></nz-pagination>
            <ng-template #totalTemplate let-total> 总共 {{totalSize}} 条 </ng-template>
        </div>
        <div nz-row class="operate_btn margin-top-16">
            <!-- <button nz-button nzType="" (click)="edit()" [disabled]="editDisabled"
                [class]="editDisabled?'ant-btn ant-btn-primary disabledBg':'ant-btn ant-btn-primary'"><i nz-icon
                    nzType="edit"></i>修改</button>
            <button nz-button nzType="" [disabled]="deleteDisabled" (click)="handleDelete()"
                [class]="deleteDisabled?'ant-btn ant-btn-primary disabledBg':'ant-btn ant-btn-primary'"><i nz-icon
                    nzType="delete"></i>删除</button> -->
            <button nz-button nzType="" [disabled]="RturnDisabled" (click)="handleReturnDetail()"
                [class]="RturnDisabled?'ant-btn ant-btn-primary disabledBg':'ant-btn ant-btn-primary'" *ngIf="returnchangeDetailRoles.edit">退回</button> 
                
            <button nz-button nzType="" [disabled]="ReplaceDisabled" (click)="handleReplace()" *ngIf="showReplace && returnchangeDetailRoles.edit"
                [class]="ReplaceDisabled?'ant-btn ant-btn-primary margin-left-16 disabledBg':'ant-btn ant-btn-primary margin-left-16'">换货请验</button> 

            <button nz-button nzType="" [disabled]="ConfirmReturnDisabled" (click)="handleConfRetAndRep()" *ngIf="showConfirmReturn && returnchangeDetailRoles.edit"
                [class]="ConfirmReturnDisabled?'ant-btn ant-btn-primary margin-left-16 disabledBg':'ant-btn ant-btn-primary margin-left-16'">确认退货</button>   

            <button nz-button nzType="" [disabled]="ConfirmReplaceDisabled" (click)="handleConfRetAndRep()" *ngIf="showConfirmReplace && returnchangeDetailRoles.edit"
                [class]="ConfirmReplaceDisabled?'ant-btn ant-btn-primary margin-left-16 disabledBg':'ant-btn ant-btn-primary margin-left-16'">确认换货</button>   

        </div>
        <nz-table #expandTable nzBordered nzTitle="退换单明细" [nzData]="detailListData" [nzFrontPagination]="false" class="margin-top-16"  nzSize="small">
            <thead>
                <tr>
                    <th colspan="1">选择</th>
                    <th>业务类型</th>
                    <th>采购订单号</th>
                    <th>物料名称</th>
                    <th>物料编码</th>
                    <th>批次</th>
                    <th>库房</th>
                    <th>库区</th>
                    <!-- <th>数量</th> -->
                    <th>生产日期</th>
                    <th>包装数量</th>
                    <th>包装规格（公斤）</th>
                    <th>重量（公斤）</th>
                    <th>退货数量</th>
                    <th>退货原因</th>
                    <th>退换货状态</th>
                    <th>请验状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let data of expandTable.data" class="trhover">
                    <td nzShowCheckbox [(nzChecked)]="data.checked" (nzCheckedChange)="checkSingleDetail(data)">
                    </td>
                    <td>
                        {{ data.returntype != null ? 
                            data.returntype == "0" ? "退货" 
                            : data.returntype == "1" ? "换货" 
                            : ""
                         : "" }}
                    </td>
                    <td>{{ data.pocode }}</td>
                    <td>{{ data.materialName }}</td>
                    <td>{{ data.materialCode }}</td>
                    <td>{{ data.barcodeBatch }}</td>
                    <td>{{ data.warehousename }}</td>
                    <td>{{ data.warehouseareaname }}</td>
                    <!-- <td>数量</td> -->
                    <td>{{ data.produceDate }}</td>
                    <td>{{ data.packageNumber }}</td>
                    <td>{{ data.packSpec }}</td>
                    <td>{{ data.weight }}</td>
                    <td>{{ data.returnnum }}</td>
                    <td>{{ data.returnDesc }}</td>
                    <td>
                        {{ data.returnstatus != null ? 
                            data.returnstatus == "0" ? "处理中" 
                        : data.returnstatus == "1" || data.returnstatus == "2" ? "退回中"
                        : data.returnstatus == "3" ? "完成"
                        : ""
                     : "" }}
                    </td>
                    <td [class]="data.checkStatus == 1 ? 'bgColor1C9ED8' 
                    : data.checkStatus == 2 ? 'bgColor008000' 
                    : data.checkStatus == 3 ? 'bgColorFF0000' 
                    : data.checkStatus == 4 ? 'bgColorFFFF00' 
                    : ''">
                        {{ data.checkStatus == 0 ? "不需要检验" 
                            : data.checkStatus == 1 ? "待检"
                            : data.checkStatus == 2 ? "合格"
                            : data.checkStatus == 3 ? "不合格"
                            : data.checkStatus == 4 ? "让步放行"
                            : "其他"}}</td>
                    <td>
                        <a href="javascript:;" (click)="showBox4(data, 2)">删除</a>&nbsp;
                        <a href="javascript:;" (click)="showAltDetailVisible(data)" *ngIf="data.returntype == 1 && data.returnstatus != 3">修改</a>
                    </td>
                </tr>
            </tbody>
        </nz-table>

        <div nz-row class="row_4" *ngIf="detailListData.length!=0" class="page_box" style="margin-top: 20px;">
            <nz-pagination (nzPageIndexChange)="detailClickPage($event)" [(nzPageIndex)]="detailPageIndex" [nzTotal]="detailTotalSize"
                [nzShowTotal]="totalTemplate"></nz-pagination>
            <ng-template #totalTemplate let-total> 总共 {{detailTotalSize}} 条 </ng-template>
        </div>
    </div>
</div>
<div id="modal_box"></div>
<nz-modal [nzStyle]="{left:'6%',top:'20px'}" appDragModal [nzGetContainer]="modalDomBox" [(nzVisible)]="isVisible" nzTitle="创建单据" nzMaskClosable="false" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()"
    [nzOkLoading]="isOkLoading" nzWidth="90%">
    <div class="returnproduct-manage">
        <div nz-row nzGutter="10" class="row_1">
            <div nz-col nzSpan="1" style="width: 96px;">
                <label class="line-height-32-prefix ant-form-item-required">业务类型：</label>
            </div>
            <div nz-col nzSpan="4">
                <nz-select nzDropdownClassName="select_custom" [(ngModel)]="BusinessType" nzPlaceHolder="请选择" class="width-10000">
                    <nz-option nzValue="" nzLabel="请选择"></nz-option>
                    <nz-option nzValue="1" nzLabel="换货单"></nz-option>
                    <nz-option nzValue="0" nzLabel="退货单"></nz-option>
                </nz-select>
            </div>
            <div nz-col nzSpan="3">
                <label class="line-height-32-prefix ant-form-item-required">采购订单号：</label>
            </div>
            <div nz-col nzSpan="4">
                <nz-select nzDropdownClassName="select_custom" [(ngModel)]="poCode" nzPlaceHolder="请选择" (ngModelChange)="addOrderChange($event)" class="width-10000">
                    <nz-option *ngFor="let poItem of selPoList" [nzLabel]="poItem.text" [nzValue]="poItem.value"></nz-option>
                </nz-select>
            </div>
        </div>
        <div nz-row class="row_2">
            <nz-table #expandTableAdd [nzData]="listDataAdd" [nzFrontPagination]="false"  nzSize="small">
                <thead>
                    <tr>
                        <th nzShowCheckbox [(nzChecked)]="isAllCheckedAdd" (nzCheckedChange)="checkAllAdd($event)"></th>
                        <th>物料编码</th>
                        <th>物料名称</th>
                        <th>批次</th>
                        <!-- <th>数量</th> -->
                        <th>库房</th>
                        <th>库区</th>
                        <th>生产日期</th>
                        <th>包装数量</th>
                        <th>包装规格（公斤）</th>
                        <th>重量（公斤）</th>
                        <th>退货数量</th>
                        <th>退货原因</th>
                    </tr>
                </thead>
                <tbody>
                    <tr *ngFor="let data of expandTableAdd.data">
                        <td nzShowCheckbox [(nzChecked)]="data.checked" (nzCheckedChange)="checkSingleAdd()">
                        </td>
                        <td>{{ data.materialCode }}</td>
                        <td>{{ data.materialName }}</td>
                        <td>{{ data.barcodeBatch }}</td>
                        <!-- <td>数量</td> -->
                        <td>{{ data.warehousename }}</td>
                        <td>{{ data.warehouseareaname }}</td>
                        <td>{{ data.produceDate }}</td>
                        <td>{{ data.packageNumber }}</td>
                        <td>{{ data.packSpec }}</td>
                        <td>{{ data.weight }}</td>
                        <td>
                            <nz-input-number [nzStep]="1" [nzMin]="1" [(ngModel)]="data.outNumber"></nz-input-number>
                        </td>
                        <td>
                            <input nz-input [(ngModel)]="data.outDesc" placeholder="输入退货原因"/>
                        </td>
                    </tr>
                </tbody>
            </nz-table>
            <div nz-row class="row_4" *ngIf="expandTableAdd.data.length!=0" class="page_box" style="margin-top: 20px;">
                <nz-pagination [nzSize]="'small'" (nzPageIndexChange)="clickPageAdd($event)" [(nzPageSize)]="pagesizeAdd"
                    [(nzPageIndex)]="pageIndexAdd" [nzTotal]="totalSizeAdd" [nzShowTotal]="totalTemplate">
                </nz-pagination>
                <ng-template #totalTemplate let-total> 总共 {{totalSizeAdd}} 条 </ng-template>
            </div>
        </div>
    </div>
</nz-modal>
<input type="hidden" [(ngModel)]="hidWarehouseId"/>
<input type="hidden" [(ngModel)]="hidWhsAreaId"/>
<nz-modal appDragModal [nzGetContainer]="modalDomBox" nzTitle="修改信息" nzMaskClosable="false" [(nzVisible)]="isAltDatailVisible" [nzOkLoading]="isOkLoading" (nzOnCancel)="altDetailCancel()" (nzOnOk)="altDetailOk()" nzWidth="760px">
    <form nz-form [formGroup]="validateDetailForm">
        <div nz-row nzGutter="16">
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>生产日期</nz-form-label>
                    <nz-form-control [nzSpan]="16" nzErrorTip="请选择生产日期">
                        <nz-date-picker nzDropdownClassName="date-range" [nzStyle]="{'width':'100%'}" class="width-10000" formControlName="txtPdData"></nz-date-picker>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>到货日期</nz-form-label>
                    <nz-form-control [nzSpan]="16" nzErrorTip="请选择到货日期">
                        <nz-date-picker nzDropdownClassName="date-range" [nzStyle]="{'width':'100%'}" class="width-10000" formControlName="txtAdData"></nz-date-picker>
                    </nz-form-control>
                </nz-form-item>
            </div>
        </div>
        <div nz-row nzGutter="16">
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>供应商批次</nz-form-label>
                    <nz-form-control [nzSpan]="16" nzErrorTip="请输入供应商批次">
                        <input nz-input formControlName="txtSupplierBatch" placeholder="请输入供应商批次" />
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>条码批次</nz-form-label>
                    <nz-form-control [nzSpan]="16" nzErrorTip="请输入条码批次">
                        <input nz-input formControlName="txtCodeBatch" placeholder="请输入条码批次" />
                    </nz-form-control>
                </nz-form-item>
            </div>
        </div>
        <div nz-row nzGutter="16">
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>包装数量</nz-form-label>
                    <nz-form-control [nzSpan]="16" nzErrorTip="请输入包装数量">
                        <input nz-input formControlName="txtPackNumber" placeholder="请输入包装数量" />
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>包装规格(公斤)</nz-form-label>
                    <nz-form-control [nzSpan]="16" nzErrorTip="请输入包装规格">
                        <input nz-input formControlName="txtPackSpec" placeholder="请输入包装规格" />
                    </nz-form-control>
                </nz-form-item>
            </div>
        </div>
        <div nz-row nzGutter="16">
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>重量(公斤)</nz-form-label>
                    <nz-form-control [nzSpan]="16" nzErrorTip="请输入重量">
                        <input nz-input formControlName="txtWeight" placeholder="请输入重量" />
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8">抽秤重量1</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="txtCheckWeight1" placeholder="请输入抽秤重量" />
                    </nz-form-control>
                </nz-form-item>
            </div>
        </div>
        <div nz-row nzGutter="16">
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8" nzRequired>库区</nz-form-label>
                    <nz-form-control [nzSpan]="16" [nzErrorTip]="selMaterialTreeErrorTpl">
                        <!-- <input nz-input formControlName="txtWhsArea" placeholder="请点击选择库区" /> -->
                        <nz-tree-select [nzDropdownStyle]="{ 'max-height': '300px', left : '-200px' }" nzAllowClear="false" formControlName="selMaterialWhsArea" 
                        [nzNodes]="selWhsTree" nzPlaceHolder="请点击选择库区" class="width-10000"></nz-tree-select>
                        <ng-template #selMaterialTreeErrorTpl let-control>
                            <ng-container *ngIf="control.hasError('required')">请选择库区</ng-container>
                            <ng-container *ngIf="control.hasError('msgWhsAreaError')">请正确选择库区</ng-container>
                        </ng-template>
                    </nz-form-control>
                </nz-form-item>
            </div>
            <div nz-col nzSpan="12">
                <nz-form-item>
                    <nz-form-label [nzSpan]="8">抽秤重量2</nz-form-label>
                    <nz-form-control [nzSpan]="16">
                        <input nz-input formControlName="txtCheckWeight2" placeholder="请输入抽秤重量" />
                    </nz-form-control>
                </nz-form-item>
            </div>
        </div>
    </form>
</nz-modal>
<nz-modal appDragModal [nzGetContainer]="modalDomBox" [(nzVisible)]="isShowBox1" nzTitle="友情提示" (nzOnCancel)="cancelBox1()" (nzOnOk)="okBox1()">
    <div nz-row>
        <p>{{checkFirstMsg}}</p>
    </div>
    <div nz-row>
        <div nz-col nzSpan="4">
            是否加急：
        </div>
        <div nz-col nzSpan="20">
            <nz-radio-group [(ngModel)]="isAnxious">
                <label nz-radio nzValue="1">是</label>
                <label nz-radio nzValue="0">否</label>
              </nz-radio-group>
        </div>
    </div>    
</nz-modal>
<nz-modal appDragModal [nzGetContainer]="modalDomBox" [(nzVisible)]="isShowBox2" class="box2_modal" nzTitle="确认信息" (nzOnCancel)="cancelBox2()" (nzOnOk)="okBox2()">
    <div nz-row>
        <h4 style="font-weight:bold">原材料</h4>
    </div>
    <nz-checkbox-wrapper style="width: 100%;" (nzOnChange)="materialChecked($event)" *ngIf="isShowBox2">
        <div nz-row nzGutter="16">
            <div nz-col nzSpan="12" *ngFor="let item of materialOptions"><label nz-checkbox [nzValue]="item.value">{{item.label}}</label></div>
        </div>
    </nz-checkbox-wrapper>
    <div nz-row>
        <h4 style="font-weight:bold;margin-top:10px">包装材料</h4>
    </div>
    <nz-checkbox-wrapper style="width: 100%;" (nzOnChange)="packageChecked($event)" *ngIf="isShowBox2">
        <div nz-row nzGutter="16">
            <div nz-col nzSpan="12" *ngFor="let item of packageStatus"><label nz-checkbox [nzValue]="item.value">{{item.label}}</label></div>
        </div>
    </nz-checkbox-wrapper>
</nz-modal>
<nz-modal [(nzVisible)]="isShowBox3" nzTitle="友情提示" (nzOnCancel)="cancelBox3()" (nzOnOk)="okBox3()">
    <p>确定要退回么？</p>
</nz-modal>
<nz-modal [(nzVisible)]="isShowBox4" nzTitle="友情提示" (nzOnCancel)="cancelBox4()" (nzOnOk)="okBox4()">
    <p>确定要删除么？</p>
</nz-modal>
<nz-modal appDragModal [nzGetContainer]="modalDomBox" [(nzVisible)]="isShowBox5" nzTitle="修改信息" (nzOnCancel)="cancelBox5()" (nzOnOk)="okBox5()">
    <div nz-row>
        <div nz-col nzSpan="4">
            <p>退货数量：</p>
        </div>
        <div nz-col nzSpan="20">
            <nz-input-number [nzStep]="1" [nzMin]="1" [(ngModel)]="returnnum"></nz-input-number>
        </div>
    </div>
    <div nz-row>
        <div nz-col nzSpan="4">
            <p>退货原因：</p>
        </div>
        <div nz-col nzSpan="20">
            <textarea rows="4" nz-input [(ngModel)]="returnDesc" placeholder="请输入拒绝原因"></textarea>
        </div>
    </div>
</nz-modal>